from flask import Blueprint,render_template,g,redirect,request,jsonify
from app import db
from app.models import Product,User,Acctproduct,Applyinfo,Updatejour
import time,random

permissions_add_page = Blueprint('permissions_add_page',__name__,template_folder='templates')
@permissions_add_page.route('/permissions-add',methods = ['GET','POST'])
def permissions_add():
    if g.user is not None and g.user.is_authenticated:
        hs_current_id = str(g.user).replace("'", "")
        hs_current_user = db.session.query(User.username).filter_by(id = hs_current_id).first()[0]
        mes_lists = db.session.query(Updatejour.output,Updatejour.update_date,Updatejour.update_time,Updatejour.message,Updatejour.id,Updatejour.log_path).filter_by(read_status = 1,up_persion=hs_current_user).all()
        mes_len = len(mes_lists)
        test_lists = [[1,2,3,4,5],[2,3,4,5,6]]

        if request.method == 'POST':
            if request.values.get('fun') == 'change':
                a = random.randint(90,100)
                b = '正在镜像'
                print(a)
                data = {'value':a,'progress':b}
                return jsonify(data)


    else:
        return redirect('/login')
    return render_template('hs-permissions-approval.html',hs_current_user=hs_current_user,mes_lists=mes_lists,mes_len=mes_len,test_lists=test_lists)
